package gui.Recebimento;

import bin.Armazem;
import bin.exc.ECadastroInvalido;
import bin.move.Movimentacao;
import bin.move.Recebimento;
import gui.JanelaPrincipal;
import java.text.DateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;

public class JanelaRecebimento extends javax.swing.JInternalFrame {
    
    private JanelaPrincipal janelaPrincipal;
    private Armazem arm;
    private int ID;
    private int item;
    private int qty;
    private int fornec;
    private String dataRec;
    private Date df;
    
    public JanelaRecebimento(JanelaPrincipal jp) {
        this.setJanelaPrincipal(jp);// 
        initComponents();
        this.setID(janelaPrincipal.getArmazem().getControleIDs().getRecebimentoID());
        jTextFieldIDRec.setText(""+ID);
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldIDRec = new javax.swing.JTextField();
        jTextFieldItemRec = new javax.swing.JTextField();
        jTextFieldQtyRec = new javax.swing.JTextField();
        jButtonReceber = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();

        setBackground(new java.awt.Color(255, 255, 255));
        setForeground(java.awt.Color.white);
        setTitle("InfosRecebimento");
        setToolTipText("");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("RECEBIMENTO DE ESTOQUE");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("ID de Recebimento:");
        jLabel2.setEnabled(false);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("Item Recebido: ");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Quantidade Recebida:");

        jTextFieldIDRec.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldIDRec.setEnabled(false);
        jTextFieldIDRec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldIDRecActionPerformed(evt);
            }
        });

        jTextFieldItemRec.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jTextFieldQtyRec.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldQtyRec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldQtyRecActionPerformed(evt);
            }
        });

        jButtonReceber.setFont(new java.awt.Font("Calibri Light", 0, 25)); // NOI18N
        jButtonReceber.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/icons/Receiving+.png"))); // NOI18N
        jButtonReceber.setText("Receber");
        jButtonReceber.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonReceberMouseClicked(evt);
            }
        });
        jButtonReceber.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonReceberActionPerformed(evt);
            }
        });

        jButtonCancelar.setFont(new java.awt.Font("Calibri Light", 0, 25)); // NOI18N
        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/icons/btCancelar.png"))); // NOI18N
        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jButtonReceber, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldIDRec, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)
                                    .addComponent(jTextFieldItemRec)
                                    .addComponent(jTextFieldQtyRec)))))
                    .addComponent(jLabel1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jSeparator1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldIDRec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldItemRec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldQtyRec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 98, Short.MAX_VALUE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonReceber)
                    .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldQtyRecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldQtyRecActionPerformed
        //// TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldQtyRecActionPerformed

    private void jButtonReceberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonReceberActionPerformed
       item = Integer.parseInt(jTextFieldItemRec.getText());
        qty = Integer.parseInt(jTextFieldQtyRec.getText());
       // fornec = Integer.parseInt(jTextFieldForRec.getText());
       //gerar move de recebimento
       // janelaPrincipal.getArmazem().getMoves().add(new Recebimento(arm, item, qty));
        /// criar estoque
        janelaPrincipal.getArmazem().buscarItem(item).setQtdEstoque(janelaPrincipal.getArmazem().buscarItem(item).getQtdEstoque() + qty);
        
    }//GEN-LAST:event_jButtonReceberActionPerformed

    private void jButtonReceberMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonReceberMouseClicked
        // Inicializar janela de confirmação
    }//GEN-LAST:event_jButtonReceberMouseClicked

    private void jTextFieldIDRecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldIDRecActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldIDRecActionPerformed

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        this.janelaPrincipal.getJanelaFactory().liberarJanela("JanelaRecebimento");
        this.dispose();
    }//GEN-LAST:event_jButtonCancelarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonReceber;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextFieldIDRec;
    private javax.swing.JTextField jTextFieldItemRec;
    private javax.swing.JTextField jTextFieldQtyRec;
    // End of variables declaration//GEN-END:variables

    public Armazem getArm() {
        return arm;
    }
    
    public void setArm(Armazem arm) {
        this.arm = arm;
    }
    
    public int getID() {
        return ID;
    }
    
    public void setID(int ID) {
        this.ID = ID;
    }
    
    public int getItem() {
        return item;
    }
    
    public void setItem(int item) {
        this.item = item;
    }
    
    public int getQty() {
        return qty;
    }
    
    public void setQty(int qty) {
        this.qty = qty;
    }
    
    public int getFornec() {
        return fornec;
    }
    
    public void setFornec(int fornec) {
        this.fornec = fornec;
    }
    
    public String getDataRec() {
        return dataRec;
    }
    
    public void setDataRec(String dataRec) {
        this.dataRec = dataRec;
    }
    
    public JanelaPrincipal getJanelaPrincipal() {
        return janelaPrincipal;
    }
    
    public void setJanelaPrincipal(JanelaPrincipal janelaPrincipal) {
        this.janelaPrincipal = janelaPrincipal;
    }
    
}
